TransportEventBusModule   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 47
dl 0
loc 64
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A forRoot 0 35 1
1
import { DynamicModule, Global, Module } from '@nestjs/common';
2
import { CqrsModule, EventBus } from '@nestjs/cqrs';
3
import { TransportEventBusService } from './transport.event-bus.service';
4
import { ModuleRef } from '@nestjs/core';
5
import { TransportEventBusPublisher } from './transport.event-bus.publisher';
6
import { TRANSPORT_EVENT_BUS_PUBLISHER, TRANSPORT_EVENT_BUS_SERVICE } from './constants/transport.event-bus.constants';
7
8
@Global()
9
@Module({
10
    imports: [
11
        CqrsModule
12
    ],
13
    providers: [
14
        {
15
            provide: TRANSPORT_EVENT_BUS_PUBLISHER,
16
            useClass: TransportEventBusPublisher
17
        },
18
        {
19
            provide: TRANSPORT_EVENT_BUS_SERVICE,
20
            useFactory: (eventBus: EventBus, moduleRef: ModuleRef) => {
21
                return new TransportEventBusService(
22
                    [],
23
                    eventBus,
24
                    moduleRef
25
                );
26
            },
27
            inject: [EventBus, ModuleRef],
28
        },
29
    ],
30
    exports: [
31
        TRANSPORT_EVENT_BUS_SERVICE,
32
        TRANSPORT_EVENT_BUS_PUBLISHER,
33
    ]
34
})
35
export class TransportEventBusModule {
36
    static forRoot(
37
        {
38
            publishers = [],
39
            providers = []
40
        }
41
    ): DynamicModule {
42
43
        return {
44
            module: TransportEventBusModule,
45
            imports: [
46
                CqrsModule
47
            ],
48
            providers: [
49
                ...publishers,
50
                ...providers,
51
                {
52
                    provide: TRANSPORT_EVENT_BUS_PUBLISHER,
53
                    useClass: TransportEventBusPublisher
54
                },
55
                {
56
                    provide: TRANSPORT_EVENT_BUS_SERVICE,
57
                    useFactory: (eventBus: EventBus, moduleRef: ModuleRef) => {
58
                        return new TransportEventBusService(
59
                            publishers,
60
                            eventBus,
61
                            moduleRef
62
                        );
63
                    },
64
                    inject: [EventBus, ModuleRef],
65
                },
66
            ],
67
            exports: [
68
                TRANSPORT_EVENT_BUS_SERVICE,
69
                TRANSPORT_EVENT_BUS_PUBLISHER,
70
                ...publishers
71
            ],
72
        };
73
    }
74
}
75